<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="box"></div>

    <script>
        var box = document.getElementById('box');
        function loadImageAsync(url){
            const promise = new Promise(function(resolve,reject){
                //异步操作
                const img = new Image();
                img.src = url;
                img.onload = function(){
                    resolve(img);
                }
                img.onerror = function(){
                    reject(new Error('图片加载失败'))
                }
            })
            return promise;
        }

        const promise = loadImageAsync('../imgs/BING.jpg');
        promise.then(function(data){
            box.appendChild(data)
        },function(error){
            box.innerHTML = '图片加载失败'
            console.log(error)
        })

    </script>
</body>
</html>